/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package alpes.aerolinea.persistencia;

import alpes.aerolinea.entities.ServicioVideoPeliculas;
import alpes.aerolinea.entities.ServicioVideoSeries;
import alpes.aerolinea.entities.ServicioVideoVideos;
import alpes.aerolineas.exceptions.NoExisteException;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Daniel
 */
@Stateless
public class PersistenciaServicesMock implements IPersistenciaServices {

    @PersistenceContext
    private EntityManager em;
    private static ArrayList sData;
    private static ArrayList pData;
    private static ArrayList vData;

    public PersistenciaServicesMock() {
    }

    public void create(Object obj) {
        em.persist(obj);
    }

    public void update(Object obj) {
        em.merge(obj);
    }

    public void delete(Object obj) {
        em.remove(em.merge(obj));
    }

    public List findAll(Class c) {
        return em.createQuery("select O from " + c.getSimpleName() + " as O").getResultList();
    }

    public Object findById(Class c, Object id) {
        return em.find(c, id);
    }
//------------------------------------------------------------------------
    @Override
    public boolean existe(Object nombreSerie) {
        return false;
    }

    public Object findByNombre(Class c, Object nombre) {
        String nom = (String) nombre;
        for (int i = 0; i < sData.size(); i++) {
            ServicioVideoSeries s = (ServicioVideoSeries) sData.get(i);
            if (s.getNombreSerie().equals(nom)) {
                return s;
            }
        }
        return null;
    }

    public Object findByID(Class c, Object id) throws NoExisteException {
        return em.find(c, id);
    }

    public boolean existeID(String nombreSerie) {
        return false;
    }
}
